/**
 * 工程名: 	Quickdisk
 * 文件名: 	FileTypeFilter.java
 * 创建人:  	guo.tianxiang
 * 创建时间: 	2014-5-8 下午2:21:27
 * 版权所有：Guo Tianxiang
 * 文件描述: 描述该文件的作用
 * -----------------------------变更记录 ----------------------------- 
 * 日期        		变更人      		版本号  		变更描述  
 * ------------------------------------------------------------------  
 * 2014-5-8     guo.tianxiang   	1.0       	first created  
 */
package com.tianxiang.action;

import java.text.ParseException;
import java.util.ArrayList;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;
import com.tianxiang.model.MyFile;
import com.tianxiang.model.User;
import com.tianxiang.service.FileFilterService;
import com.tianxiang.utils.Tools;

/**
 * 过滤指定类型文件
 * 
 * @since Quickdisk 1.1
 * @version 1.0 2014-5-8
 * @author guo.tianxiang
 */
public class FileFilterAction extends ActionSupport {

	private String fileType;
	private String key;
	private ArrayList<MyFile> listfiles;
	private static final long serialVersionUID = 1L;

	public ArrayList<MyFile> getListfiles() {
		return listfiles;
	}

	public void setListFiles(ArrayList<MyFile> listfiles) {
		this.listfiles = listfiles;
	}

	@JSON(serialize=false)
	public String getFileType() {
		return fileType;
	}

	public void setFileType(String fileType) {
		this.fileType = fileType;
	}
	@JSON(serialize=false)
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	/**
	 * 
	 * 按类型过滤用户根目录下的文件
	 * 
	 * @return
	 * @throws ParseException 
	 */
	public String listFilterFile() throws ParseException {
		FileFilterService service = new FileFilterService();
		User user = (User) ServletActionContext.getRequest().getSession()
				.getAttribute("loginuser");
		String username = user.getUsername();
		System.out.println("excute fileFilter " + fileType);
		String userroot = Tools.getUserPath(username);
		//listfiles = service.getFilterList(userroot, fileType);
		listfiles = service.getFileFilterList(user.getUsername(), fileType);
		return SUCCESS;
	}
	

	/**
	 *  列出用户回收站内的文件
	 *  @return
	 * @throws Exception 
	 */
	public String listRecycalFile() throws Exception{
		FileFilterService service = new FileFilterService();
		User user = (User) ServletActionContext.getRequest().getSession()
				.getAttribute("loginuser");
		String username=user.getUsername();
		String recycalPath=Tools.getRecycalPath(username);
		System.out.println("回收站："+recycalPath);
		listfiles = service.ListUserRecycal(recycalPath,username);
		return SUCCESS;
	}

	/**
	 * 按关键字查找根目录下的文件
	 * 
	 * @return
	 * @throws ParseException 
	 */
	public String findByKey() throws ParseException {
		FileFilterService service = new FileFilterService();
		User user = (User) ServletActionContext.getRequest().getSession()
				.getAttribute("loginuser");
		String username = user.getUsername();
		String userroot = Tools.getUserPath(username);
		System.out.println("key="+key);
		listfiles=service.findFilesByKey(userroot,username,key);
		return SUCCESS;
	}
}
